#ifndef FILE_SENDER_H
#define FILE_SENDER_H
#include <QThread>
#include <QIODevice>
#include <QHostAddress>

#include <QVector>
#include <QPair>
#include <QMutex>

#include "commons.h"

/*
Questa classe contine il thread incaricato di 
gestire il trasferimento dei file
*/
class FileSender : public QThread
{

	Q_OBJECT
	

	

public:
	FileSender(QObject *parent=0);
	~FileSender();
	
	void setParameter(bool forceJoin, QHostAddress ackAddr, quint16 ackPort, QIODevice *data, QVector<QPair<quint32, quint16>> *clients, QHostAddress addr, quint16 port, QString fileName = QString() );
	
	void stop();

protected:
	void run();
signals:
	void transferState(int completo, int giro);
private:
	QHostAddress ackAddr,groupAddr;
	quint16 ackPort,groupPort;
	QIODevice *dataBuffer;
	QString fileName;
	QVector<QPair<quint32, quint16>> *clients;
	bool termina;
	bool forceJoin;
	void sendFile();
	QMutex mutex;

};

#endif